package com.xls.minio.controller;

import com.xls.commonutils.Result;
import com.xls.minio.service.MinioService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/minio/oss")
@Api(value = "minio文件上传")
public class MinioController {

    @Autowired
    private MinioService minioService;

    @PostMapping("/upload/avatar")
    public Result<String> uploadAvatar(@RequestPart("file") MultipartFile file) {
        String url = minioService.uploadAvatar(file);
        return Result.success(url);
    }

    @PostMapping("/remove/avatar")
    public Result<String> removeAvatar(@RequestParam("filename") String filename) {
        minioService.removeAvatar(filename);
        return Result.success();
    }

    @PostMapping("/upload/room")
    public Result<String> uploadRoomImage(@RequestParam("file") MultipartFile file,
                                          @RequestParam("id") String id) {
        String url = minioService.uploadRoomImage(file, id);
        return Result.success(url);
    }

    @DeleteMapping("/remove/room")
    public Result<String> removeRoomImage(@RequestParam("filename") String filename,
                                          @RequestParam("id") String id) {
        minioService.removeRoomImage(filename, id);
        return Result.success();
    }

    @GetMapping("/get/room/{id}")
    public Result<List<String>> getRoomImage(@PathVariable("id") String id) {
        List<String> url = minioService.getRoomImage(id);
        return Result.success(url);
    }

}
